package com.example.demo_springboot.controller;
//
//import com.example.demo_springboot.dao.AccountDao;
//import com.example.demo_springboot.vo.Account;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.domain.Example;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

/*
* 基于JPA 的一个测试案例
* 这里JPA模式使用hibernate 管理持久化对象
* jpa 测试未未使用service 层,所以本项目无对应service类接口
* */
@RestController
@RequestMapping("/accountjpa")
public class AccoutJpaController {
//    @Autowired
//    AccountDao accountDao;
//
//    @RequestMapping(value = "/list", method = RequestMethod.GET)
//    public List<Account> getAccounts() {
//        return accountDao.findAll();
//    }
//
//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
//    public Account getAccountById(@PathVariable("id") int id) {
//        return accountDao.getOne(id);
//    }
//
//    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
//    public Optional<Account> getAccountById2(@PathVariable("id") int id) {
//        return accountDao.findById(id);
//    }
//
//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
//    public List<Account> deleteById(@PathVariable("id") int id) {
//        accountDao.deleteById(id);
//        return accountDao.findAll();
//    }
//
//    @RequestMapping(value = "/findOne/{id}", method = RequestMethod.GET)
//    public Optional<Account> getAccountById3(@PathVariable("id") int id) {
//        Account account = new Account();
//        account.setId(id);
//        Example<Account> ex= Example.of(account);
//        return accountDao.findOne(ex);
//    }
//
//    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
//    public String updateAccount(@PathVariable("id") int id, @RequestParam(value = "name", required = true) String name,
//                                @RequestParam(value = "money", required = true) double money) {
//        Account account = new Account();
//        account.setMoney(money);
//        account.setName(name);
//        account.setId(id);
//        Account account1 = accountDao.saveAndFlush(account);
//
//        return account1.toString();
//
//    }
//
//    @RequestMapping(value = "", method = RequestMethod.POST)
//    public String postAccount(@RequestParam(value = "name") String name,
//                              @RequestParam(value = "money") double money) {
//        Account account = new Account();
//        account.setMoney(money);
//        account.setName(name);
//        Account account1 = accountDao.save(account);
//        return account1.toString();
//
//    }
}
